<?php
/**
 * Course Class Model
 *
 * Copyright 2012
 * @date 21-April-2012
 * @author 
 * @version 0.0.1
 **/
class CustomerInterest extends AppModel {
/**
 * Name
 *
 * @var string
 */
    public $name = 'CustomerInterest';
    public $useTable = "customers_interests";
    public $belongsTo = array(
        'Customer'=>array(
            'className'=>'Customer',
            'foreignKey'=>'customer_id'
        ),
        'Interest'=>array(
            'className'=>'Interest',
            'foreignKey'=>'interest_id'
        )
    );
    
    public function get_interest_by_customer($customer_id) {
        $this->unbindModel(array("belongsTo"=>array("Customer")));
        return $this->find("all",array('conditions'=>array('customer_id'=>$customer_id)));
    }
    public static function count_customer_by_interest($interest_id) {
        $sq = ClassRegistry::init("CustomerInterest");
        return $sq->find("count",array('conditions'=>array('interest_id'=>$interest_id)));
    }
    public function get_customer_by_interest($customer_id) {
        $this->unbindModel(array("belongsTo"=>array("Customer")));
        return $this->find("all",array('conditions'=>array('customer_id'=>$customer_id)));
    }
    public function delete_interest_by_customer($customer_id) {
        return $this->query("Delete from customers_interests where customer_id=$customer_id");
    }
    public function delele_customer_by_interest($interest_id) {
        return $this->query("Delete from customers_interests where interest_id=$interest_id");
    }
    public function delete_customer_interest($customer_id,$interest_id) {
        return $this->query("Delete from customers_interests where customer_id=$customer_id AND interest_id=$interest_id");
    }
    public static function check_question($surveys_id,$question_id){
        $sq = ClassRegistry::init("CustomerInterest");
        $check = $sq->find("all",array('conditions'=>array('surveys_id'=>$surveys_id,'questions_id'=>$question_id)));
        if(!empty($check)){
            return 1;
        }
        return 0;
    }
}